package com.sanrenzu.chunbo.ui.vertical.like;

import android.content.Context;
import android.content.Intent;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

import com.sanrenzu.chunbo.R;
import com.sanrenzu.chunbo.adapter.LikeAdapter;
import com.sanrenzu.chunbo.adapter.ShangPinAdapter;
import com.sanrenzu.chunbo.adapter.XiangQingFramentAdapter;
import com.sanrenzu.chunbo.bean.zxb.DianJiLikeBean;
import com.sanrenzu.chunbo.bean.zxb.ShouYeDianJiBean;
import com.sanrenzu.chunbo.config.UrlConfig;
import com.sanrenzu.chunbo.ui.fenlei.xiangqing.XiangQingFragment;
import com.sanrenzu.chunbo.ui.vertical.fenlei.FenLeiContractA;
import com.sanrenzu.chunbo.ui.vertical.fenlei.FenLeiPersenterA;
import com.sanrenzu.chunbo.widget.MyGirdView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

public class LikeActivity extends AppCompatActivity implements LikeContract.View{

    //VIEWPAGER 图片及下方价格   控件初始化
    @BindView(R.id.fenlei_viewpager_main)
    ViewPager fenleiViewpagerMain;
    @BindView(R.id.fenlei_jiashao_main)
    TextView fenleiJiashaoMain;
    @BindView(R.id.fenlei_jiashao_main2)
    TextView fenleiJiashaoMain2;
    @BindView(R.id.fenlei_jiage_main)
    TextView fenleiJiageMain;
    @BindView(R.id.fenlei_chunbojiage_main)
    TextView fenleiChunbojiageMain;
    @BindView(R.id.fenlei_girdview_main)
    MyGirdView fenleiGirdviewMain;

    //图文详情页 控件初始化
    @BindView(R.id.fenlei_second_viewpager)
    ViewPager fenleiSecondViewpager;
    @BindView(R.id.fenlei_second_tablayout)
    TabLayout fenleiSecondTablayout;

    private ShangPinAdapter shangPinAdapter;
    private LikeAdapter likeAdapter;
    //persenter内部方法调用
    private LikeContract.Persenter persenterA;
    // 黄油刀对象声明
    private Unbinder bind;
    private Context context = this;
    //tablayout标题设置
    private String[] arrayTabs;
    //动态创建碎片
    private List<Fragment> mListFragment = new ArrayList<>();
    //详情页适配器
    private XiangQingFramentAdapter xiangQingFramentAdapter;

    public String id="";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fen_lei);

        Intent intent = getIntent();
        id = intent.getStringExtra("id");
        Map<String,String> map = new HashMap<>();
        map.put(UrlConfig.Key.PRODUCT_ID,id);

        bind = ButterKnife.bind(this);
        persenterA = new LikePresenter(this);
        persenterA.getVerticalShouYe(map);

        initView();
    }

    @Override
    public void onGetVerticalDianJiTuPianBean(ShouYeDianJiBean dianJiTuPianBean) {
        List<String> productContentImagesWH = dianJiTuPianBean.getProductImages();
        List<DianJiLikeBean> productRecommendedList = dianJiTuPianBean.getProductRecommendedList();
        //viewpager下面的属性控件声明
        fenleiJiashaoMain.setText(dianJiTuPianBean.getAdTitle());
        fenleiJiashaoMain2.setText(dianJiTuPianBean.getProductName());
        fenleiJiageMain.setText(dianJiTuPianBean.getProductMarketPrice() + "");
        fenleiChunbojiageMain.setText(dianJiTuPianBean.getProductHotPrice() + "");
        //设置适配器，viewpager和猜你喜欢
        shangPinAdapter = new ShangPinAdapter(context, productContentImagesWH);
        likeAdapter = new LikeAdapter(context, productRecommendedList);

        fenleiGirdviewMain.setAdapter(likeAdapter);
        fenleiViewpagerMain.setAdapter(shangPinAdapter);


    }

    private void initView() {
        arrayTabs = getResources().getStringArray(R.array.tabTiles);
        for (int i = 0; i < arrayTabs.length; i++) {
            XiangQingFragment fragment = XiangQingFragment.newInstance(i);
            mListFragment.add(fragment);
        }
        xiangQingFramentAdapter = new XiangQingFramentAdapter(getSupportFragmentManager(), mListFragment, arrayTabs);
        fenleiSecondViewpager.setAdapter(xiangQingFramentAdapter);
        fenleiSecondTablayout.setupWithViewPager(fenleiSecondViewpager);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        bind.unbind();
    }

}
